package cn.ratel.db;

import com.google.common.base.CaseFormat;
import com.google.common.base.Preconditions;

import java.util.LinkedHashMap;
import java.util.Map;

class Table {
	Map<String, Column> columns = new LinkedHashMap<>();
	Class<?> clazz;
	// LOWER_UNDERSCORE ！！！
	String name;

	Table(Class<?> clazz) {
		this(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, clazz.getSimpleName()));
		this.clazz = clazz;
	}

	Table(String name) {
		for (char c : name.toCharArray()) {
			if (Character.isLetter(c)) {
				Preconditions.checkArgument(Character.isLowerCase(c), "table naming must be LOWER_UNDERSCORE !");
			}
		}
		this.name = name;
	}

	void addColumn(Column column) {
		columns.put(column.name, column);
	}

	boolean contains(String columnName) {
		return columns.containsKey(columnName);
	}

}
